/*
 * ArCoLIVE - Live Internet Videoconference Environment
 * Information Technology Departament - Federal University of Alagoas - Brazil
 *
 * Copyright (C) 2005 Leandro Melo de Sales (leandro@labpesquisas.tci.ufal.br)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package br.ufal.tci.nexos.arcolive;

import java.util.Hashtable;
import java.util.Map;

import br.ufal.tci.nexos.arcolive.descriptors.ServiceInstanceDescriptor;
import br.ufal.tci.nexos.arcolive.exception.ArCoLIVECannotAddParticipantException;
import br.ufal.tci.nexos.arcolive.exception.ArCoLIVECannotStartServiceException;
import br.ufal.tci.nexos.arcolive.exception.ArCoLIVECannotStopServiceException;
import br.ufal.tci.nexos.arcolive.participant.ArCoLIVEParticipant;
import br.ufal.tci.nexos.arcolive.participant.ArCoLIVEParticipantGroup;

/**
 * CLASSNAME.java
 *
 * CLASS DESCRIPTION
 *
 * @see CLASSNAME
 *
 * @author <a href="mailto:felipe@labpesquisas.tci.ufal.br">Felipe Barros Pontes</a>.
 * @author <a href="mailto:leandro@labpesquisas.tci.ufal.br">Leandro Melo de Sales</a>.
 * @since 0.1
 * @version 0.1
 *
 * <p><b>Revisions:</b>
 *
 * <p><b>yyyymmdd USERNAME:</b>
 * <ul>
 * <li> VERSION
 * </ul>
 */
public abstract class ArCoLIVEServiceInstance {
	
	private ServiceInstanceDescriptor serviceInstanceDescriptor;
	private ServiceStatus serviceStatus;
	private Map attributes;
	protected ArCoLIVEParticipantGroup participantGroup;

	public ArCoLIVEServiceInstance() {
		this.serviceInstanceDescriptor = null;
		this.serviceStatus = new ServiceStatus();
		this.attributes = new Hashtable();
	}
	
	public ArCoLIVEServiceInstance(int serviceId, int serviceInstanceId, String name, String description, int maxParticipant, Map additionalParameters) {
		this.serviceInstanceDescriptor = new ServiceInstanceDescriptor(serviceId, serviceInstanceId);
		this.serviceInstanceDescriptor.setName(name);
		this.serviceInstanceDescriptor.setDescription(description);
		this.serviceStatus = new ServiceStatus();
		this.attributes = additionalParameters;
		this.participantGroup = new ArCoLIVEParticipantGroup(maxParticipant);
	}
	
	public ServiceInstanceDescriptor getServiceInstanceDescriptor() {
		return this.serviceInstanceDescriptor;
	}
	
	public ServiceStatus getServiceStatus() {
		return serviceStatus;
	}

	public void setServiceStatus(int statusId) {
		this.serviceStatus.setStatusId(statusId);
	}
	
	public void addAttribute(String attributeName, Object attributeValue) {
		this.attributes.put(attributeName, attributeValue);
	}
	
	public String getAttribute(String attributeName) {
		return (String) this.attributes.get(attributeName);
	}
	
	public Object getObjectAttribute(String attributeName) {
		return this.attributes.get(attributeName);
	}
	
	public int getIntAttribute(String attributeName) {
		return Integer.parseInt((String) this.attributes.get(attributeName));
	}
	
	public Integer getIntegerAttribute(String attributeName) {
		return new Integer ((String) this.attributes.get(attributeName));
	}
	
	public void removeAttribute(String attributeName) {
		this.attributes.remove(attributeName);
	}
	
	public ArCoLIVEParticipantGroup getParticipantGroup() {
		return participantGroup;
	}
	
	public abstract void addParticipant(ArCoLIVEParticipant participant) throws ArCoLIVECannotAddParticipantException;
	public abstract void removeParticipant(ArCoLIVEParticipant participant);
	public abstract void startService() throws ArCoLIVECannotStartServiceException;
	public abstract void stopService() throws ArCoLIVECannotStopServiceException;
	
}
